//
//  WDPDDefaultCell.m
//  Zhihuijinfu
//
//  Created by 王笛 on 2016/12/27.
//  Copyright © 2016年 王笛. All rights reserved.
//

#import "WDPDDefaultCell.h"
#import "WDPDBottom.h"
#import "WDPDLeftBottom.h"

@interface WDPDDefaultCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *leftLabel;
@property (weak, nonatomic) IBOutlet UILabel *valueLabel;

@end

@implementation WDPDDefaultCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    //图片自适应
    self.iconView.contentMode = UIViewContentModeScaleAspectFit;
}

+ (instancetype)defaultCellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"defaultCell";
    WDPDDefaultCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (!cell) {
        
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
        
    }
    return cell;
}

- (void)setBottom:(WDPDBottom *)bottom
{
    _bottom = bottom;
    
    self.valueLabel.text = bottom.value;
    
    [self layoutIfNeeded];
    
    [self layoutIfNeeded];
    
    CGRect frame = self.frame;
    
    CGRect newFrame = CGRectMake(frame.origin.x, frame.origin.y, WDScreenW, frame.size.height);
    
    self.frame = newFrame;
    
    [self layoutIfNeeded];
    
    bottom.cellHeight = CGRectGetMaxY(self.valueLabel.frame) + 11;
}

- (void)setLeftBottom:(WDPDLeftBottom *)leftBottom
{
    _leftBottom = leftBottom;
    
    self.iconView.image = [UIImage imageNamed:leftBottom.icon];
    
    self.leftLabel.text = leftBottom.intro;
}

@end
